package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/permission")
@RestController
@Slf4j
public class PermissionController {


    @Reference
    PermissionService permissionService;

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean  queryPageBean){
    log.debug("分页查询，请求体："+ queryPageBean);

       PageResult pageResult =  permissionService.findPage(queryPageBean);

    return new Result(true,"查询成功",pageResult);


    }

    /**
     * 编辑
     * @param
     * @return
     */
    @RequestMapping("/edit")
    public Result edit(@RequestBody Permission  permission ){
         permissionService.edit(permission);

        return new Result(true,"编辑成功");
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){

    Permission permission = permissionService.findById(id);
    return new Result(true,"请编辑或取消",permission);
    }
    /**
     * 添加
     * @param permission
     * @return
     */
    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission){


          permissionService.add(permission);

        return new Result(true,MessageConst.ADD__PERMISSION_SUCCESS);


    }
@RequestMapping("/delete")
    public Result delete(Integer id)
{
    permissionService.delete(id);
    return new Result(true,MessageConst.DELETE_PERMISSION_SUCCESS);


}

}
